package br.com.agenda.web.client;

import br.com.agenda.web.client.constant.LoginConstants;
import br.com.agenda.web.client.popup.CadastroUsuarioPopUp;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;

public class Login implements EntryPoint {
	/**
	 * Create a remote service proxy to talk to the server-side Greeting
	 * service.
	 */
	private final GreetingServiceAsync	greetingService	= GWT.create(GreetingService.class);
	
	public void onModuleLoad() {
		LoginConstants constants = GWT.create(LoginConstants.class);
		
		DecoratorPanel decorator = new DecoratorPanel();
		
		FlexTable layLogin = new FlexTable();
		layLogin.setCellSpacing(6);
		
		FlexCellFormatter cellLogin = layLogin.getFlexCellFormatter();
		cellLogin.setColSpan(0, 0, 2);
		cellLogin.setColSpan(3, 0, 2);
		cellLogin.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		cellLogin.setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
		cellLogin.setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
		cellLogin.setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
		
		layLogin.setHTML(0, 0, constants.hdTitulo());
		
		TextBox txNome = new TextBox();

		layLogin.setHTML(1, 0, constants.lbNome());
		layLogin.setWidget(1, 1, txNome);
		
		PasswordTextBox txSenha = new PasswordTextBox();
		
		layLogin.setHTML(2, 0, constants.lbSenha());
		layLogin.setWidget(2, 1, txSenha);
		
		Button btnEntrar = new Button(constants.btEntrar());
		
		Button btnCadastrar = new Button(constants.btNovo());
		btnCadastrar.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				CadastroUsuarioPopUp popup = new CadastroUsuarioPopUp();
				popup.setGlassEnabled(true);
				popup.center();
				popup.show();
			}
		});
		
		HorizontalPanel hControl = new HorizontalPanel();
		hControl.setSpacing(5);
		hControl.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		hControl.add(btnCadastrar);
		hControl.add(btnEntrar);
		
		layLogin.setWidget(3, 0, hControl);
		
		decorator.setWidget(layLogin);
		
		RootPanel.get("content").add(decorator);
	}
}
